package com.zyx.springmvcmsb.advanced.controller;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author zyx
 * @since 2021/10/5 09:52
 */
@Controller
public class EntityController {

    @RequestMapping("/testHttpEntity")
    public String testHttpEntity(HttpEntity<String> httpEntity) {
        System.out.println("httpEntity =====>>>>> " + httpEntity);
        String body = httpEntity.getBody();
        System.out.println("body =====>>>>> " + body);
        return "success";
    }

    /**
     * 自定义响应相关的信息, 包含body和header
     */
    @RequestMapping("/testResponseEntity")
    public ResponseEntity<String> testResponseEntity() {
        String str = "<h1>hello,springmvc</h1>";
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("Set-Cookie", "name=zhangsan");
        return new ResponseEntity<>(str, httpHeaders, HttpStatus.OK);
    }

}
